/*
 * test1
 */
package com.pitop.repair.ctrl;


import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

import com.pitop.core.exceptions.BaseException;
import com.pitop.core.entity.BeanRet;
import com.pitop.core.entity.Page;
import com.pitop.core.tools.redis.RedisUtils;
import com.pitop.repair.entity.RepairStaff;
import com.pitop.repair.service.RepairStaffSVImpl;

/**
 * 维修账户 控制器
 *
 * @author test1
 */
@RestController
@RequestMapping("/repairStaff")
@Slf4j
@Api(value = "维修账户控制器", description = "维修账户控制器")
public class RepairStaffCtrl {

    @Resource
    protected RedisUtils redisUtils;
    @Autowired
    private RepairStaffSVImpl repairStaffSVImpl;


    /**
     * 查询RepairStaff一个详情信息
     *
     * @param id
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询RepairStaff一个详情信息", notes = "查询RepairStaff一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(Long id, String code) {
        if (id == null) {
            return BeanRet.create(false, BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isBlank(code)) {
            return BeanRet.create(false, BaseException.BaseExceptionEnum.Empty_Param);
        }
        RepairStaff repairStaff = repairStaffSVImpl.load(id, code);
        log.info(JSON.toJSONString(repairStaff));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, repairStaff);
    }


    /**
     * 根据条件id查询RepairStaff一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询RepairStaff一个详情信息", notes = "查询RepairStaff一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable Long id) {
        if (id == null || id == 0) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        RepairStaff repairStaff = repairStaffSVImpl.loadById(id);
        log.info(JSON.toJSONString(repairStaff));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, repairStaff);
    }

    /**
     * 根据条件code查询RepairStaff一个详情信息
     *
     * @param code 编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询RepairStaff一个详情信息", notes = "查询RepairStaff一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/code/{code}")
    @ResponseBody
    public BeanRet loadByCode(@PathVariable String code) {
        if (StringUtils.isEmpty(code)) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        RepairStaff repairStaff = repairStaffSVImpl.loadByCode(code);
        log.info(JSON.toJSONString(repairStaff));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, repairStaff);
    }


    /**
     * 查询RepairStaff信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询RepairStaff信息集合", notes = "查询RepairStaff信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),

            @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTimeBegin", value = "更新时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTimeEnd", value = "更新时间", paramType = "query")
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore RepairStaff repairStaff, @ApiIgnore Page<RepairStaff> page) {
        if (page == null) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        List<RepairStaff> repairStaffs = repairStaffSVImpl.list(repairStaff, page.getCurPage(), page.getPageSize());
        int total = repairStaffSVImpl.count(repairStaff);
        page.setTotalRow(total);
        page.setVoList(repairStaffs);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, "", page);
    }


    /**
     * 查询RepairStaff信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询RepairStaff信息集合", notes = "查询RepairStaff信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(Long id, String code, @ApiIgnore Page<RepairStaff> page) {
        if (page == null) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        List<RepairStaff> repairStaffs = repairStaffSVImpl.list(id, code, page.getCurPage(), page.getPageSize());
        int total = repairStaffSVImpl.count(id, code);
        page.setTotalRow(total);
        page.setVoList(repairStaffs);
        log.info(JSON.toJSONString(page));
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, "", page);
    }

    /**
     * 创建RepairStaff
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建RepairStaff", notes = "创建RepairStaff")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "邮箱", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码 md5 加密", paramType = "query"),
            @ApiImplicitParam(name = "jobnumber", value = "工号 0000四位格式", paramType = "query"),
            @ApiImplicitParam(name = "lastName", value = "姓", paramType = "query"),
            @ApiImplicitParam(name = "firstName", value = "名", paramType = "query"),
            @ApiImplicitParam(name = "gender", value = "性别：男 Male，女 Female，其他 Other", paramType = "query"),
            @ApiImplicitParam(name = "avatar", value = "头像", paramType = "query"),
            @ApiImplicitParam(name = "countryCode", value = "国家代码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "timezone", value = "所在时区", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：激活[Activate]，冻结[Frozen]，删除[Delete]", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore RepairStaff repairStaff) {
        if (StringUtils.isEmpty(repairStaff.getEmail())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getPassword())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getJobnumber())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getLastName())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getFirstName())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getGender())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getAvatar())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getCountryCode())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getLanguage())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getTimezone())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getState())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (repairStaff.getCreateTime() == null) {
            repairStaff.setCreateTime(new Date());
        }
        repairStaffSVImpl.save(repairStaff);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, repairStaff);
    }


    /**
     * 修改RepairStaff
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改RepairStaff", notes = "修改RepairStaff")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query"),
            @ApiImplicitParam(name = "email", value = "邮箱", paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码 md5 加密", paramType = "query"),
            @ApiImplicitParam(name = "jobnumber", value = "工号 0000四位格式", paramType = "query"),
            @ApiImplicitParam(name = "lastName", value = "姓", paramType = "query"),
            @ApiImplicitParam(name = "firstName", value = "名", paramType = "query"),
            @ApiImplicitParam(name = "gender", value = "性别：男 Male，女 Female，其他 Other", paramType = "query"),
            @ApiImplicitParam(name = "avatar", value = "头像", paramType = "query"),
            @ApiImplicitParam(name = "countryCode", value = "国家代码", paramType = "query"),
            @ApiImplicitParam(name = "language", value = "语言", paramType = "query"),
            @ApiImplicitParam(name = "timezone", value = "所在时区", paramType = "query"),
            @ApiImplicitParam(name = "state", value = "状态：激活[Activate]，冻结[Frozen]，删除[Delete]", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "updateTime", value = "更新时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore RepairStaff repairStaff) {
        if (StringUtils.isEmpty(repairStaff.getEmail())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getPassword())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getJobnumber())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getLastName())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getFirstName())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getGender())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getAvatar())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getCountryCode())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getLanguage())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getTimezone())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (StringUtils.isEmpty(repairStaff.getState())) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        if (repairStaff.getUpdateTime() == null) {
            repairStaff.setUpdateTime(new Date());
        }
        repairStaffSVImpl.modify(repairStaff);
        return BeanRet.create(true, BaseException.BaseExceptionEnum.Success, repairStaff);
    }

    /**
     * 根据主键删除RepairStaff
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除RepairStaff", notes = "删除RepairStaff")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "code", value = "编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(Long id, String code) {
        if (id != null && StringUtils.isEmpty(code)) {
            return BeanRet.create(BaseException.BaseExceptionEnum.Empty_Param);
        }
        repairStaffSVImpl.delete(id, code);
        return BeanRet.create(true, "删除RepairStaff成功");
    }


}
